﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using T4._4.Models;

namespace T4._4.Controllers
{
    public class LoginController : Controller
    {
        private SchoolEntities _context;
        public LoginController()
        {
            _context = new SchoolEntities();
        }
        // GET: Index
        [HttpPost]
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Index(string UserName,string UserPwd)
        {
            var user = _context.Users.SingleOrDefault(x => x.UserName == UserName);
            if (user==null)
            {
                ViewBag.msg = "用户不存在";
            }
            else
            {
                if (user.UserPwd==UserPwd)
                {
                    Session["user"] = user;
                }
                else
                {
                    ViewBag.msg = "用户名或密码错误，请重新输入";
                }
            }
            return View();
        }
    }
}